from src import WR_config,Device_config
from src import Device_pvname_data,Device_host_data,Device_type_data,Device_MC_data
from .Device_opr import *
WR_data = {}
for key,value in WR_config.items():
    WR_data[value] = key

Device_data = {}
for pvname in Device_pvname_data:
    for  key,value in Device_config.items():
        Device_data[value.format(pvname)] = key

Device_host = {}
for pvname,host in Device_host_data.items():
    for  key,value in Device_config.items():
        Device_host[value.format(pvname)] = host

Device_type = {}
for pvname,type in Device_type_data.items():
    for  key,value in Device_config.items():
        Device_type[value.format(pvname)] = type

MC_data = {}
for pvname,MC in Device_MC_data.items():
    for  key,value in Device_config.items():
        MC_data[value.format(pvname)] = MC

def IOC_opr(pvname, value):
        if pvname in WR_data.keys():
            if WR_data[pvname] == "频率设定":
                FREQ_Set()
            elif WR_data[pvname] == "触发设定":
                trigger(value)
            elif WR_data[pvname] == "复位":
                reset()
        elif pvname in Device_data.keys():
            host = Device_host[pvname]
            type = Device_type[pvname]
            MC = 0
            if type == "Mulit" or type == "Master":
                MC = int(MC_data[pvname])
            if Device_data[pvname] == "脉宽":
                Width(host, type, value, MC)
            elif Device_data[pvname] == "延时":
                Delay(host, type, value, MC)
            elif Device_data[pvname] == "联锁Bypass":
                Opr_Bypass(host,type,value)
            elif Device_data[pvname] == "初始化":
                init(host, type)

